//树形dp - Nearby Cows G
#include <iostream>
#include <vector>
using namespace std;
const int N = 100010;
int f[N][25]; //f[x][k]表示从x节点出发, 向下走k步, 能够覆盖的节点权值之和
int g[N][25]; //g[x][k]表示从x节点出发, 向上向下走k步, 能够覆盖的节点权值之和
int n, k;
int c[N];
vector<int> edges[N];

void dfs1(int x, int fa)
{
	//初始化
	for (int i = 0; i <= k; i++) f[x][i] = c[x];

	for (auto y : edges[x])
	{
		if (y == fa) continue;
		dfs1(y, x);
		for (int i = 1; i <= k; i++) f[x][i] += f[y][i - 1];
	}
}

void dfs2(int x, int fa)
{
	for (auto y : edges[x])
	{
		if (y == fa) continue;
		g[y][0] = f[y][0];
		g[y][1] = f[y][1] + g[x][0];
		for (int i = 2; i <= k; i++) 
			g[y][i] = f[y][i] + g[x][i - 1] - f[y][i-2];
		dfs2(y, x);
	}
}

int main()
{
	cin >> n >> k;
	for (int i = 1; i < n; i++)
	{
		int x, y; cin >> x >> y;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	for (int i = 1; i <= n; i++) cin >> c[i];
	dfs1(1, 0);
	for (int i = 0; i <= k; i++) g[1][i] = f[1][i];
	dfs2(1, 0);
	for (int i = 1; i <= n; i++) cout << g[i][k] << endl;
	return 0;
}

//空间优化版本:
#include <iostream>
#include <vector>
using namespace std;
const int N = 100010;
int f[N][25];
int n, k;
int c[N];
vector<int> edges[N];

void dfs1(int x, int fa)
{
	//初始化
	for (int i = 0; i <= k; i++) f[x][i] = c[x];

	for (auto y : edges[x])
	{
		if (y == fa) continue;
		dfs1(y, x);
		for (int i = 1; i <= k; i++) f[x][i] += f[y][i - 1];
	}
}

void dfs2(int x, int fa)
{
	for (auto y : edges[x])
	{
		if (y == fa) continue;
		for (int i = k; i >= 2; i--) 
			f[y][i] += f[x][i - 1] - f[y][i-2];
		f[y][1] += f[x][0];
		dfs2(y, x);
	}
}

int main()
{
	cin >> n >> k;
	for (int i = 1; i < n; i++)
	{
		int x, y; cin >> x >> y;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	for (int i = 1; i <= n; i++) cin >> c[i];
	dfs1(1, 0);
	dfs2(1, 0);
	for (int i = 1; i <= n; i++) cout << f[i][k] << endl;
	return 0;
}